<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>reduce练习</title>
    <style>
      * {
        padding: 0px;
        margin: 0px;
      }
      body {
        font-size: 12px;
        height: 100vh;
        width: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: #34495e;
      }
      div {
        font-size: 3rem;
        font-weight: bold;
        text-transform: uppercase;
        color: #8e44ad;
      }
      div > span {
        position: relative;
        display: inline-block;
      }
      .color {
        animation: color 1s linear 2 alternate;
      }
      @keyframes color {
        50% {
          color: #f1c40f;
          transform: scale(2);
        }
        100% {
          color: #f39c12;
          transform: scale(0.5);
        }
      }
    </style>
  </head>
  <body>
    <div>anyun-cangge.com</div>
  </body>
  <script>
    const div = document.querySelector('div')
    let textContentArray = [...div.textContent]
    textContentArray.reduce((pre, cur, index) => {
      pre === index && (div.innerHTML = '')
      let span = document.createElement('span')
      span.innerHTML = cur
      div.appendChild(span)
      span.addEventListener('mouseover', (event) => {
        event.target.classList.add('color')
      })
      span.addEventListener('animationend', (event) => {
        event.target.classList.remove('color')
      })
    }, 0)
  </script>
</html>
